﻿using System.Collections.ObjectModel;

namespace jq9602_jq9603.Process
{
    internal class Products : ObservableCollection<TestItem>
    {
        public void Init()
        {
            foreach (var item in Items)
            {
                for (int i = 0; i < TestItem.StationCount; i++)
                {
                    item.StationIsPassed[i] = null;
                    item.StationValue[i] = 0;
                }
            }
        }

        public TestItem FindByDesc(string desc)
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].Desc == desc)
                    return this[i];
            }
            throw new Exception($"未找到[{desc}]测试项");
        }

        public void SetItemResult(string desc, double value)
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].Desc == desc)
                {
                    for (int j = 0; j < TestItem.StationCount; j++)
                    {
                        this[i].SetResult(j, value);
                    }
                    return;
                }
            }
            throw new Exception($"未找到[{desc}]测试项");
        }

        public void SetItemResult(string desc, int stationIndex, double value)
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].Desc == desc)
                {
                    this[i].SetResult(stationIndex, value);
                    return;
                }
            }
            throw new Exception($"未找到[{desc}]测试项");
        }
    }
}